<!doctype html>

<head>
    <!-- meta -->
    <meta charset="utf-8">
    <meta name="description" content="Flat, Clean, Responsive, admin template built with bootstrap 3">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1, maximum-scale=1">
    <!-- /meta -->

    <title>心秘籍系统</title>


    <bstablecss />
    <commonheader />
</head>
<body>

<div class="app">

    <!-- top header -->
    <include file="Common/header_nav" />
    <!-- /top header -->

    <section class="layout">
        <div class="panel panel-primary">
            <div class="panel-heading">
                上传评测问卷
            </div>

            <div class="panel-body">
                <div class="row">
                    <div class="col-md-7">
                        <form role="form">
                            <div class="form-group">
                                <label>选择问卷类型：</label>
                                <select id="quiz_file_type" class="form-control">
                                    <option>分值型（scoreType）</option>
                                    <option>统计型（countType）</option>
                                </select>

                                <label>问卷文件</label>
                                <div><a class="btn btn-success" id="quiz-file-btn">上传问卷文件</a></div>
                                <input class="form-control mg-b-md" type="file" id="quiz-file" multiple="true" style="display: none;">
                            </div>
                        </form>
                    </div>

                    <div class="col-md-9">
                        <label>内置问卷列表</label>
                        <div class="table-responsive">
                            <table class="table table-bordered table-striped">
                                <thead>
                                <tr>
                                    <th>问卷ID</th>
                                    <th>问卷名</th>
                                    <th>添加用户</th>
                                    <th>添加时间</th>
                                    <th>类型</th>
                                    <th>因子等级</th>
                                </tr>
                                </thead>

                                <tbody>

                                <foreach name="bulidin_quiz" item="r">
                                    <tr>
                                        <td>{$r.quiz_id}</td>
                                        <td>{$r.quiz_name}</td>
                                        <td>管理员</td>
                                        <td>{$r.add_time}</td>
                                        <td>16pf表格型</td>
                                        <td>{$r.divisor_level}</td>
                                    </tr>
                                </foreach>

                                </tbody>
                            </table>
                        </div>
                        <label>自定义问卷列表</label>
                        <div class="table-responsive">
                            <table class="table table-bordered table-striped">
                                <thead>
                                <tr>
                                    <th>问卷ID</th>
                                    <th>问卷名</th>
                                    <th>添加用户</th>
                                    <th>添加时间</th>
                                    <th>类型</th>
                                    <th>因子等级</th>
                                    <th>操作</th>
                                </tr>
                                </thead>

                                <tbody>

                                <foreach name="custom_quiz" item="r">
                                    <tr>
                                        <td>{$r.quiz_id}</td>
                                        <td>{$r.quiz_name}</td>
                                        <td>管理员</td>
                                        <td>{$r.add_time}</td>
                                        <td>16pf表格型</td>
                                        <td>{$r.divisor_level}</td>
                                        <td><a class="btn btn-danger btn-sm" target="_blank" href="__URL__/deleteQuiz/quiz_id/{$r.quiz_id}">删除问卷</a></td>
                                    </tr>
                                </foreach>

                                </tbody>
                            </table>
                        </div>
                    </div>

                </div>
            </div>
        </div>
    </section>

</div>


<!-- /问卷确认信息对话框 -->
<div class="modal fade" id="quiz-confirm" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" data-keyboard="false">
    <div class="modal-dialog" >
        <div class="modal-content">
            <div class="modal-header">
                确认文件信息<a id="add-user-classinfo"></a>
            </div>
            <div class="modal-body" >
                <div class="row">



                    <div class="col-md-12">
                        <div class="panel-body">
                            <form role="form">
                                <div class="form-group">
                                    <label>问卷标题</label>
                                    <input class="form-control mg-b-md" type="text" id="sourcename-input" placeholder="输入标题（不能和已有问卷重复）">
                                    <textarea rows="15" cols="30" id="quiz-confirm-textarea" class="form-control"></textarea>
                                    <label>问卷页面标题</label>
                                    <input class="form-control mg-b-md" type="text" id="pagetitle-input" placeholder="输入页面标题">
                                    <label>问卷基本描述</label>
                                    <textarea rows="10" cols="30" id="quiz-introduce" class="form-control"></textarea>
                                    <label>问卷温馨提示</label>
                                    <textarea rows="10" cols="30" id="quiz-tips" class="form-control"></textarea>

                                </div>
                            </form>
                        </div>
                    </div>
                </div>

            </div>
            <div class="modal-footer" ><a class="btn btn-success" id="quizsource-save">保存问卷</a></div>
        </div>

    </div>
</div>


<commonfooter />
<bstablejs />
<jqnestablejs />
<script src="__PUBLIC__/asset/vendor/bootstrap-table/bootstrap-table.min.js"></script>
<script src="__ROOT__/Public/asset/vendor/jquery.uploadify.min.js" type="text/javascript"></script>
<script src="__PUBLIC__/js/adminQuizUpload.js"></script>
<script>
//    $('#quiz-file').uploadify({
//        'buttonText': '点我上传文件',
////            'fileSizeLimit':'2MB',
//        'swf'       : '__PUBLIC__/uploadify.swf',
//        'uploader'  : '/Home/Admin/testUpload',
//            'cancelImg ': '__ROOT__/Public/cancel.png',
//        'onUploadSuccess' : function(file, data, response) {
//            var htmls = [''];
//
//            data = jQuery.parseJSON(data);
//
//            if(data.code!=1)//文件失败提示错误信息并刷新页面
//            {
//                alert((data.msg));
////                htmls.push('<p>'+data+'</p>');
////                $("#failed-list").html((htmls.join('')));
////                //alert(data);
////                //window.location='';
//            }
//            else{
//                //alert("上传成功");
//                $("#quiz-confirm-textarea").val(data.log);
//                $("#quiz-confirm").modal('show');
//
//
//            }
//        },
//        'onQueueComplete'  : function() {
//            //window.location='';
//        }
//    });


$("#quiz-file-btn").click(function(){
    $("#quiz-file").trigger('click');
});



$("#quiz-file").change(function(){
    var quiz_file_type;
    //$("#quiz_file_type").get(0).selectedIndex
    if ($("#quiz_file_type").get(0).selectedIndex == 0){
        quiz_file_type = "score";
    }
    else{
        quiz_file_type = "count";
    }


    $.ajax({
        type: "POST",
        url: '/TestAdmin/ManageQuiz/setQuizType',
        dataType: "json",
        async: false,
        data: {
            quiz_type:quiz_file_type
        },
        success: function (data) {

        }, error: function (jqXHR) {
            alert("设置问卷类型failed" + jqXHR.status);
        }
    });


    var fd = new FormData();
    //console.log($("#xls-upload-all")[0].files[0]);
    fd.append( 'file', $("#quiz-file")[0].files[0] );

    $.ajax({
        url: '/TestAdmin/ManageQuiz/testUpload' ,
        type: 'POST',
        data: fd,
        async: false,
        cache: false,
        contentType: false,
        processData: false,
        success: function (data) {

            $("#quiz-confirm-textarea").val(data.log);
            $("#quiz-confirm").modal('show');
        },
        error: function (returndata) {
            alert("上传文件失败："+returndata.jqXHR);

        }
    });


});



    $("#quizsource-save").click(function(){
        $.ajax({
            type: "POST",
            url: "/TestAdmin/ManageQuiz/testsourceSave",
            dataType: "json",
            async: false,
            data:{
              sourcename: $("#sourcename-input").val(),

                pagetitle_input:  $("#pagetitle-input").val(),
                quiz_introduce: $("#quiz-introduce").val(),
                quiz_tips:$("#quiz-tips").val()

            },
            success: function (data) {
                alert(data.msg);
                location.reload();

            }, error: function (jqXHR) {
                alert("failed" + jqXHR.status);
            }
        });
    });


</script>
